﻿using System;

using System.Web;

namespace good1.Web.Controllers.Infrastructure
{
    /// <summary>
    /// http://www.codethinked.com/post/2008/12/04/Using-SystemWebAbstractions-in-Your-WebForms-Apps.aspx
    /// </summary>
    public static class HttpContextFactory
    {
        [ThreadStatic]
        private static HttpContextBase _mockHttpContext;

        public static void SetHttpContext(HttpContextBase httpContextBase)
        {
            _mockHttpContext = httpContextBase;
        }

        public static void ResetHttpContext()
        {
            _mockHttpContext = null;
        }

        public static HttpContextBase GetHttpContext()
        {
            if (_mockHttpContext != null)
            {
                return _mockHttpContext;
            }

            if (HttpContext.Current != null)
            {
                return new HttpContextWrapper(HttpContext.Current);
            }
            return null;
        }
    }
}
